Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line dash API #1225

Merged
merged 6 commits into from
Feb 4, 2022
Merged

Add line dash API #1225

merged 6 commits into from
Feb 4, 2022

Conversation

tarkah
Copy link
Member

@tarkah tarkah commented Jan 27, 2022

This PR adds LineDash configuration to Stroke and uses RepeatedPattern from lyon_algorithms to closely mimic the HTML Canvas APIs for adding stroked line dash styling.

I've updated the Solar System example to use a dashed line pattern for the orbit, which I think showcases this well.

A couple comments / questions:

  • Stroke is no longer Copy, I see no way around this
  • LineDash is only considered if segments is not empty. Should we instead use an Option?
  • I've added no rail-guards to validate segments, as things may not render properly if negative or non-finite values are used. It is up to the caller to define this properly.
  • If an odd number of segments are provided, they are concatenated again to the end. This is in line w/ the html canvas spec.

Relevant canvas API spec:
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-setlinedash

Screenshot:
image

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

I have made a couple of changes:

  • Replaced the Vec for segments with a simple slice by adding a lifetime to LineDash and Stroke in f56c8a7. This way, users can avoid reallocating on every draw and we get to keep the Copy trait!
  • Removed the direct lyon_algorithms dependency in bace264, as we can access it through lyon already.

Let me know what you think and we can merge this 🥳

@hecrj hecrj added canvas feature New feature or request rendering widget labels Feb 3, 2022
@hecrj hecrj added this to the 0.4.0 milestone Feb 3, 2022
@tarkah
Copy link
Member Author

tarkah commented Feb 3, 2022

Changes look great, good call on the short lifetime and slice usage!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants